home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.19981211-19990422 / 000427_news@watsun.cc.columbia.edu _Wed Mar 31 11:20:37 1999.msg < prev    next >
Internet Message Format  |  2020-01-01  |  3KB

  1. Return-Path: <news@watsun.cc.columbia.edu>
  2. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
  3.     by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id LAA21243
  4.     for <kermit.misc@watsun.cc.columbia.edu>; Wed, 31 Mar 1999 11:20:36 -0500 (EST)
  5. Received: (from news@localhost)
  6.     by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id KAA13731
  7.     for kermit.misc@watsun.cc.columbia.edu; Wed, 31 Mar 1999 10:59:01 -0500 (EST)
  8. X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
  9. From: dn5006@my-dejanews.com
  10. Subject: SWITCH statement considered harmful
  11. Date: Wed, 31 Mar 1999 15:09:20 GMT
  12. Organization: Deja News - The Leader in Internet Discussion
  13. Message-ID: <7dtdqo$tg8$1@nnrp1.dejanews.com>
  14. To: kermit.misc@watsun.cc.columbia.edu
  15.  
  16. ; In languages such as Kermit script, Tcl script, C, etc. , the switch
  17. ; statement could be the source of subtle bugs caused by the intentional or
  18. ; unintentional omission of the break statement.
  19. ;
  20. ; 'Using C-Kermit' 2nd, page 385, displays a classical usage of the switch
  21. ; statement with the intentional omission of the break statement to achieve a
  22. ; "fall-through".
  23. ; This programming way is error prone and should be avoided.
  24. ;
  25. ; Consider the following alternative which is more defensive and maintenance
  26. ; friendly, since:
  27. ; 1. New cases if any can be added easily.
  28. ; 2. No break statement is needed to terminate a case.
  29. ; 3. Fall through is explicit through the specification of the targeted case,
  30. ;    which can be any of the possible cases, even backward, skip intermitten
  31. ;    cases, whatever.
  32. ; 4. Each case label is expressive.
  33. ; 5. Default statement is replaced with the check on fail.
  34. ; 6. No subtle bugs caused by the implementation of the switch statemnet.
  35. ;
  36. ; Kermit scripting language is not C. When programming in Kermit, use Kermit
  37. ; idioms, don't mimic C.
  38.  
  39. define weekday {
  40.  
  41.     local day_0 day_1 day_2 day_3 day_4 day_5 day_6
  42.  
  43.     define day_0 { echo Sonntag }
  44.     define day_1 { echo Montag und uebermorgen ist, day_3 }
  45.     define day_2 { echo Dienstag und zunaechst kommt ..., day_3 }
  46.     define day_3 { echo Mittwoch }
  47.     define day_4 { echo Donnerstag }
  48.     define day_5 { echo Freitag und gestern war, day_4}
  49.     define day_6 { echo Samstag und da ist schon wieder der, day_0}
  50.  
  51.     day_\v(nday)
  52.     if fail echo Invalid day - \v(nday)
  53.  
  54. }
  55.  
  56. ; This is object-oriented programming in the small, the day_ is generic, when
  57. ; appended with a case specific value, it yields the name of a predefined
  58. macro, ; and get executed. This flexibility is very effective.
  59.  
  60. Dat Nguyen
  61. Airline Telecommunications and Information Services
  62. 770 Sherbrooke West
  63. Montreal, Quebec
  64. Canada H3A 1G1
  65. Email dat.nguyen&sita.int
  66.  
  67. -----------== Posted via Deja News, The Discussion Network ==----------
  68. http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
  69.